using Furion.DatabaseAccessor;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

using Tool;

namespace Abc.Core.Entities
{
    /// <summary>
    /// 功能
    /// </summary>
    [TablePrefix("Web.")]
    [Comment("功能/Action")]
    public class Permission : CreateEntity, IEntityTypeBuilder<Permission>, IEntitySeedData<Permission>
    {
        /// <summary>
        /// 类型代码：例如 Admin、API
        /// </summary>
        [Comment("类型代码")]
        public string TypeCode { get; set; }

        /// <summary>
        /// 控制器
        /// </summary>
        [Comment("控制器")]
        public string Controller { get; set; }

        /// <summary>
        /// 控制器描述
        /// </summary>
        [Comment("控制器描述")]
        public string ControllerDescription { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Comment("名称")]
        public string Name { get; set; }

        /// <summary>
        ///  后台菜单页面名称(例如：index、info),API 接口可为空
        /// </summary>

        /// <summary>
        /// 方法/Action名称,多个用英文逗号隔开
        /// </summary>
        [Comment("方法/Action名称,多个用英文逗号隔开")]
        public string Actions { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [Comment("备注")]
        public string Remark { get; set; }

        /// <summary>
        /// 是否系统菜单,系统菜单禁止删除
        /// </summary>
        [Comment("是否系统菜单")]
        public bool IsSystem { get; set; }

        /// <summary>
        /// 是否废止
        /// </summary>
        public bool IsDisuse { get; set; }

        /// <summary>
        /// 是否自动生成
        /// 通过贴特性完成为自动生成 true
        /// 后台人工添加为 false
        /// </summary>
        [Comment("是否自动生成")]
        public bool IsAutoGeneration { get; set; }

        ///// <summary>
        ///// 菜单Id
        ///// </summary>
        //[Comment("菜单Id")]
        //public int? MenuId { get; set; }

        //public Menu Menu { get; set; }

        public ICollection<Role> Roles { get; set; }

        /// <summary>
        /// 角色功能
        /// </summary>
        public ICollection<RolePermission> RolePermissions { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public ICollection<Menu> Menus { get; set; }

        /// <summary>
        /// 菜单权限中间表
        /// </summary>
        public ICollection<MenuPermission> MenuPermissions { get; set; }

        public void Configure(EntityTypeBuilder<Permission> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            //entityBuilder.HasOne(o => o.Menu).WithMany(o => o.Permissions).HasForeignKey(o => o.MenuId);
        }

        public IEnumerable<Permission> HasData(DbContext dbContext, Type dbContextLocator)
        {
            return new List<Permission>()
            {
            };
        }
    }
}